import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';
import 'package:smart_translator/app/storage/StorageManager.dart';
import 'package:smart_translator/app/utils/CommonUtil.dart';
import 'package:smart_translator/app/widgets/CommonWidgets.dart';

import '../../../const/AppConst.dart';
import '../../../event/DataCallBack.dart';
import '../../../nets/NetWorkManager.dart';
import '../../../routes/app_pages.dart';
import '../../../style/widget_style.dart';
import '../../../utils/tips.dart';
import '../../../widgets/AppHeader.dart';
import '../controllers/mine_profile_controller.dart';
import '../views/pageWidgets.dart';
import '../views/upload_avatar.dart';

class MineProfileView extends GetView<MineProfileController> {
  const MineProfileView({super.key});

  Widget build(BuildContext context) {
    return SafeArea(child: Scaffold(
      resizeToAvoidBottomInset: false,
      body: Obx(
            () => Container(
          child:
          Stack(
            children: [
              AppHeader.obtainHeaderWithoutRightPart('账号和资料'),
              Container(
                height: 250.h,
                child:  Center(
                  child: AvatarScreen(
                    controller.name.value,
                    controller.avatar.value,
                    controller.id.value,
                  ),
                ),),


              Container(
                width: Get.width,
                margin: EdgeInsets.only(top: 250.h, left: 10.w, right: 10.w),
                padding: EdgeInsets.all(18.w),
                decoration: BoxDecoration(
                  boxShadow: [
                    CommonWidgets.getBoxShadow(),
                  ],
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(
                    8,
                  ), // Optional: add border radius
                ),

                child: Column(
                  children: [
                    Container(
                        color: Colors.blueAccent.withValues(alpha: 0),
                        child:
                        GestureDetector(onTap: () {
                          pageWidgets.showDialogPart(
                            context,
                            controller.name.value,
                            controller.editName,
                          );
                        },child:  Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text(
                                  '昵称',
                                  style: AppStyleThemeData.BUTTON_TEXT_STYLE,
                                ),
                              ],
                            ),
                            Expanded(child: Text(
                                controller.name.value,
                                style: AppStyleThemeData.HINT_TEXT_STYLE,
                                textAlign: TextAlign.end
                            )),
                            Image.asset(
                              'assets/images/icon_mine_right_item.png',
                              width: 24.w,
                              height: 24.h,
                            ),
                          ],
                        ),)

                    ),
                    SizedBox(height: 12.h),
                    CommonWidgets.getMyDivider(),
                    SizedBox(height: 12.h),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            GestureDetector(
                              onTap: () {
                                Get.toNamed(Routes.NO_FOUND_DEVICE);
                              },
                              child: Text(
                                '登录方式',
                                style: AppStyleThemeData.BUTTON_TEXT_STYLE,
                              ),
                            ),
                          ],
                        ),
                        Image.asset(
                          'assets/images/icon_mine_right_item.png',
                          width: 24.w,
                          height: 24.h,
                        ),
                      ],
                    ),
                    SizedBox(height: 12.h),
                    CommonWidgets.getMyDivider(),
                    SizedBox(height: 12.h),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Text(
                              '管理我的登录',
                              style: AppStyleThemeData.BUTTON_TEXT_STYLE,
                            ),
                          ],
                        ),
                      ],
                    ),
                    SizedBox(height: 12.h),
                  ],
                ),
              ),
              Container(
                width: Get.width,
                margin: EdgeInsets.only(top: 420.h),
                padding: EdgeInsets.all(20.w),
                child: Column(
                  children: [
                    Row(children: [
                      Expanded(
                        child: ElevatedButton(
                          onPressed: () {
                            controller.loginOut();
                          },
                          child: Text('退出登录',style:TextStyle(color: Color.fromARGB(255,138,138,142))),
                          style: ButtonStyle(
                            backgroundColor: MaterialStateProperty.all<Color>(Color.fromARGB(255,229,229,229)), // 设置背景颜色为灰色
                          ),
                        ),
                      )

                    ],),
                  ],
                ),
              ),
              Positioned(
                  bottom: 20,
                  child:
                  Column(children: [
                    SizedBox(
                        width: MediaQuery.of(context).size.width,
                        child:
                        Padding(padding: EdgeInsets.all(20.0),
                          child:
                          ElevatedButton(
                            onPressed: () {
                              controller.deleteAccount();
                            },
                            child: Text('删除账号',style:TextStyle(color: Color.fromARGB(255,255,49,65))),
                            style: ButtonStyle(
                              backgroundColor: MaterialStateProperty.all<Color>(Color.fromARGB(255,229,229,229)), // 设置背景颜色为灰色
                            ),
                          ),)
                    ),

                    Center(child: RichText(text: TextSpan(
                      style: DefaultTextStyle.of(context).style,
                      children: <TextSpan>[
                        TextSpan(text: '警告：', style: TextStyle(color: Colors.red)),
                        TextSpan(text: '您的账号信息和所有文件将被永久删除',style:TextStyle(color: Color.fromARGB(255,138,138,142))),
                      ],
                    ),)
                    ),

                  ],)
              ),
            ],
          ),
        ),
      ),



    ),top: false,);
  }
}
